package com.uuj.project.net;

import android.view.View;

import com.uuj.project.utils.ExceptionHandle;
import com.uuj.project.view.IBaseView;

import io.reactivex.subscribers.ResourceSubscriber;

/**
 * ProjectName:    ok_rxjava_retrofit
 * Package:        com.uuj.project.net
 * ClassName:      CommonSubscriber
 * Description:    描述
 * Author:         张继
 * CreateDate:     2019/8/8 12:05
 * UpdateUser:     更新者
 * UpdateDate:     2019/8/8 12:05
 * UpdateRemark:   更新说明
 * Version:        1.0
 */
public abstract class CommonSubscriber<T> extends ResourceSubscriber<T> {
    private IBaseView view;

    protected CommonSubscriber(IBaseView view) {
        this.view = view;
    }

    
    @Override
    protected void onStart() {
        super.onStart();
        if (view != null) {
            view.showDialog();
        }
    }

    @Override
    public void onError(Throwable e) {
        ExceptionHandle.ResponseThrowable throwable;
        //后台逻辑执行失败，抛出的异常
        if (e instanceof ExceptionHandle.ResponseThrowable) {
            throwable = (ExceptionHandle.ResponseThrowable) e;
        } else {
            //网络操作执行的异常
            throwable = ExceptionHandle.handleException(e);
        }
        if (view != null) {
            view.showMsg(throwable.message, 1);
        }
    }

    @Override
    public void onComplete() {

    }

}
